home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr35 / qname31.zip / QNAME.C < prev    next >
C/C++ Source or Header  |  1991-03-15  |  2KB  |  67 lines

  1. /* QName -- renames ATBBS.QWK in current directory to new file name
  2.     that contains current day and month.  Written by Martin Leon,
  3.     Ashton Tate Software Support using the Microsoft Quick C compiler.  */
  4.  
  5. #include <stdio.h>
  6. #include <io.h>
  7. #include <dos.h>
  8.  
  9. FILE *oldfile;
  10. FILE *newfile;
  11. struct dosdate_t today;
  12.  
  13. char newname[13];
  14. int x;
  15.  
  16. int main()
  17. {
  18.    /* Make sure ATBBS.QWK exists */
  19.    if( ( oldfile = fopen( "ATBBS.QWK", "rt" ) ) == NULL ) {
  20.       printf( "\nNo ATBBS.QWK in current directory\n" );
  21.       return 1;
  22.     }
  23.     else
  24.         /* The file exists and is open. Close it */
  25.         fclose( oldfile );
  26.  
  27.     /* Get today's date */
  28.     _dos_getdate( &today );
  29.  
  30.     /* x = letter of the alphabet.  Start at "A", ASCII 65 */
  31.     x = 65;
  32.  
  33.     /* Use sprintf() to combine the month and day and the letter in to
  34.         a file name.  Check to see if it doesn't exist and rename. Do this
  35.         until letter = "Z" */
  36.     do {
  37.       sprintf( newname, "AT%02u%02u%c.QWK", today.month, today.day, x );
  38.  
  39.         if( ( newfile = fopen( newname, "rt" ) ) == NULL ) {
  40.  
  41.             /* File name doesn't exist, rename original to unused file name */
  42.             if( rename( "ATBBS.QWK", newname ) != 0 ) {
  43.                 printf( "\nError renaming ATBBS.QWK to %s\n" );
  44.                 return 1;
  45.             }
  46.             else
  47.                 /* If the rename was succesful, we're done with this loop */
  48.                 break;
  49.         }
  50.         else
  51.             /* If the file existed, close it and go to next file name */
  52.             fclose( newfile );
  53.    } while ( ++x <= 90 );
  54.  
  55.     /* If more than 26 files exist for today's date, give error message */
  56.     if( x > 90 ) {
  57.         printf( "\nUnable to rename beyond AT%02u%02u%c.QWK",
  58.             today.month, today.day, x - 1 );
  59.         return 1;
  60.     }
  61.  
  62.     /* Rename completed */
  63.    printf( "\nATBBS.QWK renamed to %s\n", newname );
  64.    return 0;
  65. }
  66.  
  67.